<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
信息来源 <select name="sourceId">
    <c:forEach items="${sourceList}" var="source">
        <option value="${source.id}">${source.name}</option>
    </c:forEach>
</select>
人员状态 <select name="statusId">
    <c:forEach items="${statusList}" var="status">
        <option value="${status.id}">${status.name}</option>
    </c:forEach>
</select>

<button onclick="bing()">点击展示饼状图</button>
<button onclick="excel()">点击导出</button>

<div id="main" style="width: 600px;height: 600px"></div>

</body>

<script>

    function excel() {
        let sourceId = $('[name=sourceId]').val();
        let statusId = $('[name=statusId]').val();

        location.href = 'excel.do?sourceId=' + sourceId +'&statusId=' + statusId
    }

function bing() {
    let sourceId = $('[name=sourceId]').val();
    let statusId = $('[name=statusId]').val();



    $.ajax({
        url:'bing.do?sourceId=' + sourceId +'&statusId=' + statusId,
        success:function (data) {

            console.log(data)

            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                title: {
                    text: 'Referer of a Website',
                    subtext: 'Fake Data',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '50%',
                        data: data,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };

            option && myChart.setOption(option);


        }
    })
}


</script>
</html>